package com.seven.good.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

/**
 * <h3>easyauction</h3>
 *
 * @author : 王胜奔
 * @description : 发送邮件类
 * @date : 2019-11-02 09:51
 **/
@Component
public class SendMail {
    @Autowired
    JavaMailSenderImpl sender;

    /**发送邮件验证码*/
    public void sendEmailVertification(String mail, String msg,Integer type) throws MessagingException {
        MimeMessage message = sender.createMimeMessage();
        //使用helper可以发送html、文件等
        MimeMessageHelper helper = new MimeMessageHelper(message);
        //用什么邮箱发送
        helper.setFrom("370284190@qq.com");
        //发到哪个邮箱里
        helper.setTo(mail);
        //设置主题防止被接收方识别为垃圾邮件
        helper.setSubject("用户提醒");
        String con = "";
        if (type !=null && type == 3){//开拍提醒
            con = "<html><head><meta charset=\"utf-8\"><title></title></head>" +
                    "<body><i>尊敬的用户：</i><br><p style=\"text-indent:2em\">本次您设置的拍品名称为：</p>" +
                    "<p style=\"text-indent:2em\"><b>"+msg+"</b></p>"+
                    "<p style=\"text-indent:2em\">，将于30分钟后开始</p>"+
                    "</body></html>";
        }
        if (type !=null && type == 2){//结束提醒
            con = "<html><head><meta charset=\"utf-8\"><title></title></head>" +
                    "<body><i>尊敬的用户：</i><br><p style=\"text-indent:2em\">本次您设置的拍品名称为：</p>" +
                    "<p style=\"text-indent:2em\"><b>"+msg+"</b></p>"+
                    "<p style=\"text-indent:2em\">，将于30分钟后结束</p>"+
                    "</body></html>";
        }
        if (type !=null && type == 6){//退还保证金提醒
            con = "<html><head><meta charset=\"utf-8\"><title></title></head>" +
                    "<body>" +
                    "<p style=\"text-indent:2em\"><b>"+msg+"</b></p>"+
                    "</body></html>";
        }
        if (type !=null && type == 7){//流拍提醒
            con = "<html><head><meta charset=\"utf-8\"><title></title></head>" +
                    "<body>" +
                    "<p style=\"text-indent:2em\"><b>"+msg+"</b></p>"+
                    "</body></html>";
        }

        //执行发送
        helper.setText(con,true);

        sender.send(message);
    }
}
